package com.gujiangbo.application.log;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import com.gujiangbo.application.log.support.HttpInfoBillEvt;

@Service
public class HttpInfoBillBuilder {
	private static Log debugLog = LogFactory.getLog(HttpInfoBillBuilder.class);
	private static HttpInfoBillBuilder builder;

	public static HttpInfoBillBuilder getInstance() {
		if (builder == null) {
			builder = new HttpInfoBillBuilder();
		}
		return builder;
	}

	public void billBulder(HttpInfoBillEvt logInfBillEvt) {
		StringBuffer logsb = new StringBuffer();
		if (logInfBillEvt != null) {
			try {
				logsb.append(logInfBillEvt.getReturnCode() == null ? "" : logInfBillEvt.getReturnCode());
				logsb.append("|");
				logsb.append(logInfBillEvt.getInfname() == null ? "" : logInfBillEvt.getInfname());
				logsb.append("|");
				logsb.append(logInfBillEvt.getFlowDirect() == null ? "" : logInfBillEvt.getFlowDirect());
				logsb.append("|");
				logsb.append(logInfBillEvt.getReceiveTime() == null ? "" : logInfBillEvt.getReceiveTime());
				logsb.append("|");
				logsb.append(logInfBillEvt.getResponseTime() == null ? "" : logInfBillEvt.getResponseTime());
				logsb.append("|");
				logsb.append(logInfBillEvt.getUseTime() == null ? "" : logInfBillEvt.getUseTime());
				logsb.append("|");
				logsb.append(logInfBillEvt.getReqHeader() == null ? "" : logInfBillEvt.getReqHeader());
				logsb.append("|");
				logsb.append(logInfBillEvt.getReqBodyParam().toString().trim());
				logsb.append("|");
				logsb.append(StringUtils.isBlank(logInfBillEvt.getResponseParam()) ? "":logInfBillEvt.getResponseParam().toString().trim());
				logsb.append("|");
				logsb.append(logInfBillEvt.getReturnMsg());
				logsb.append("|");
				logsb.append(logInfBillEvt.getTraceid());
				debugLog.debug(logsb.toString());
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
